<template>
  <!-- form 表单 -->
  <form class="form-inline" @submit.prevent="addTask">
    <div class="input-group mb-2 mr-sm-2">
      <!-- 输入框前缀 -->
      <div class="input-group-prepend">
        <div class="input-group-text">任务</div>
      </div>
      <!-- 文本输入框 -->
      <input type="text" class="form-control" placeholder="请输入任务信息" v-model.trim="taskname" />

      <!-- 添加按钮 -->
      <button type="submit" class="btn btn-primary mb-2">添加新任务</button>
    </div>
  </form>
</template>

<script>
export default {
  name: 'TodoInput',
  data() {
    return {
      taskname: ''
    };
  },
  emits: ['toAddTask'],
  methods: {
    addTask() {
      if (this.taskname == '') return alert('任务名称不能为空!');
      this.$emit('toAddTask', this.taskname);
      this.taskname = '';
    }
  }
};
</script>

<style scoped>
</style>